# Maintainer: David Runge <dvzrv@archlinux.org>

_name=torrentool
pkgname=python-torrentool
pkgver=1.2.0
pkgrel=1
pkgdesc="The tool to work with torrent files"
arch=(any)
url="https://github.com/idlesign/torrentool"
license=(BSD)
depends=(python)
makedepends=(
  python-build
  python-installer
  python-setuptools
  python-wheel
)
checkdepends=(
  python-pytest
  python-pytest-datafixtures
  python-pytest-responsemock
)
optdepends=(
  'python-click: for torrentool'
  'python-requests: for some torrentool subcommands'
)
source=(https://files.pythonhosted.org/packages/source/${_name::1}/$_name/$_name-$pkgver.tar.gz)
sha512sums=('166dec377586fb2d5d3dea73b4ca17f6280d89ef106790871452833d1881aed2cefb56deb830fad9243b8d0147eebc6af4b28d7668a5dbc49041291679439fa9')
b2sums=('9d304638ed02243b2a3fb1b5bd86570ac9dd82dbdc74a82ee2b00de3fbe96ce1e4ee7bf046a28934f2122132b3d770107e9ffa9a372d27aa6dbb8ae5ef0e0ff6')

build() {
  cd $_name-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  local pytest_options=(
    -vv
  )
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $_name-$pkgver
  # install to temporary location, as importlib is used
  python -m installer --destdir=test_dir dist/*.whl
  export PYTHONPATH="$PWD/test_dir/$site_packages:$PYTHONPATH"
  pytest "${pytest_options[@]}"
}

package() {
  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 {AUTHORS,CHANGELOG,README.rst} -t "$pkgdir/usr/share/doc/$pkgname/"
  install -vDm 644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
}
